const Sequelize = require('sequelize');
module.exports = function (sequelize, DataTypes) {
  return sequelize.define('m_tenants', {
    id: {
      autoIncrement: true,
      type: DataTypes.BIGINT,
      allowNull: false,
      primaryKey: true,
      comment: 'auto id'
    },
    uid: {
      type: DataTypes.BLOB,
      allowNull: true,
      defaultValue: Sequelize.Sequelize.literal('uuid_to_bin(uuid(),1)'),
      comment: 'uid'
    },
    tenant_name: {
      type: DataTypes.STRING(100),
      allowNull: true,
      comment: '租户名称',
      unique: 'idx_tenant_name'
    },
    remark: {
      type: DataTypes.STRING(500),
      allowNull: true,
      comment: '描述'
    },
    company: {
      type: DataTypes.STRING(100),
      allowNull: true,
      comment: '公司名称'
    },
    logo: {
      type: DataTypes.STRING(500),
      allowNull: true,
      comment: 'logo图片url'
    },
    state: {
      type: DataTypes.SMALLINT,
      allowNull: true,
      defaultValue: 1,
      comment: '状态1 启用0禁用'
    },
    province: {
      type: DataTypes.STRING(100),
      allowNull: true,
      comment: '一级行政单位,如广东省,上海市等'
    },
    city: {
      type: DataTypes.STRING(100),
      allowNull: true,
      comment: '城市, 如广州市,佛山市等'
    },
    district: {
      type: DataTypes.STRING(100),
      allowNull: true,
      comment: '行政区,如番禺区,天河区等'
    },
    street: {
      type: DataTypes.STRING(200),
      allowNull: true,
      comment: '街道乡镇'
    },
    address: {
      type: DataTypes.STRING(200),
      allowNull: true,
      comment: '地址'
    },
    adcode: {
      type: DataTypes.STRING(8),
      allowNull: true,
      comment: '邮政编码'
    },
    link_man: {
      type: DataTypes.STRING(100),
      allowNull: true,
      comment: '联系人'
    },
    link_phone: {
      type: DataTypes.STRING(100),
      allowNull: true,
      comment: '联系电话'
    },
    expire_time: {
      type: DataTypes.BIGINT,
      allowNull: true,
      comment: '费员过期时间'
    },
    source: {
      type: DataTypes.STRING(200),
      allowNull: true,
      comment: '来源'
    },
    history: {
      type: DataTypes.JSON,
      allowNull: true,
      comment: '历史'
    },
    create_time: {
      type: DataTypes.BIGINT,
      allowNull: true,
      comment: '创建时间'
    },
    create_user_id: {
      type: DataTypes.INTEGER,
      allowNull: true,
      comment: '创建人id'
    },
    create_user_name: {
      type: DataTypes.STRING(100),
      allowNull: true,
      comment: '创建人名'
    },
    modify_time: {
      type: DataTypes.BIGINT,
      allowNull: true,
      comment: '修改时间'
    },
    modify_user_id: {
      type: DataTypes.INTEGER,
      allowNull: true,
      comment: '修改人id'
    },
    modify_user_name: {
      type: DataTypes.STRING(100),
      allowNull: true,
      comment: '修改人名'
    }
  }, {
    sequelize,
    tableName: 'm_tenants',
    timestamps: false,
    freezeTableName: true,
    indexes: [
      {
        name: 'PRIMARY',
        unique: true,
        using: 'BTREE',
        fields: [
          { name: 'id' }
        ]
      },
      {
        name: 'idx_tenant_name',
        unique: true,
        using: 'BTREE',
        fields: [
          { name: 'tenant_name' }
        ]
      },
      {
        name: 'idx_uide',
        using: 'BTREE',
        fields: [
          { name: 'uid' }
        ]
      }
    ]
  });
};
